import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LXW
 * Date: 2022-02-16
 * Time: 15:27
 */
class Card {
    private int rank; // 牌面值
    private String suit; // 花色

    public Card (int rank,String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    public String toString() {
        return"[ "+this.suit+":"+this.rank+" ]";
    }
}
class Test {
    public static List<Card> buyCard() {
        List<Card> cards = new ArrayList<>();
        String[] suit = {"♥","♦","♠","♣"};
        for (int i = 0; i < suit.length; i++) {
            for (int j = 0; j <= 13; j++) {
                cards.add(new Card(j,suit[i]));
            }
        }
        return cards;
    }
    public static void shuffle(List<Card> cards) {
        int size = cards.size();
        for (int i = size -1; i > 0 ; i--) {
            Random random = new Random();
            int rand = random.nextInt(i);
            swap(cards,i,rand);
        }
    }
    public static void swap(List<Card> cards,int i,int rand){
        Card tmp = cards.get(i);
        cards.set(i,cards.get(rand));
        cards.set(rand,tmp);
    }
    public static void main(String[] args) {
        List<Card> cards = buyCard();
        System.out.println("买牌："+ cards);
        shuffle(cards);
        System.out.println("洗牌："+ cards);
        System.out.println("发牌：");
        // 三个人，每个人轮流抓 5 张牌
        ArrayList<List<Card>> hands = new ArrayList<>();
        List<Card> hands1 = new ArrayList<>();
        List<Card> hands2 = new ArrayList<>();
        List<Card> hands3 = new ArrayList<>();
        hands.add(hands1);
        hands.add(hands2);
        hands.add(hands3);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                hands.get(j).add(cards.remove(0));
            }
        }
        System.out.println("第1个人的牌："+hands1);
        System.out.println("第2个人的牌："+hands2);
        System.out.println("第3个人的牌："+hands3);
        System.out.println("剩下的牌："+cards);
    }

}
